package CheckersApplet;

import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;

import javax.swing.*;
import jade.core.AID;

public class CheckersGUI extends Frame {

	// TextArea textBox;
	private CheckersPanel checkers;
	private CheckersAgent myAgent;

	public CheckersGUI(CheckersAgent checkersAgent) {
		super(checkersAgent.getLocalName());

		myAgent = checkersAgent;

		setLayout(null);
		checkers = new CheckersPanel();
		checkers.resize(400, 400);
		// textBox = new TextArea(5, 40);

		add(checkers);
		// add(textBox);

		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				myAgent.doDelete();
			}
		});

		setResizable(false);
	}

	public void setThougnss(int t) {
		checkers.setToughness(t);
	}

	public void setColor(String c) {
		checkers.setColor(c);
	}

	public GameState getGameState() {
		return checkers.getGameState();
	}

	public void showGui() {
		resize(400, 425);
		checkers.setBounds(0, 25, 400, 400);
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		int centerX = (int) screenSize.getWidth() / 2;
		int centerY = (int) screenSize.getHeight() / 2;
		setLocation(centerX - getWidth() / 2, centerY - getHeight() / 2);
		super.setVisible(true);

	}

	public ArrayList<Move> newGame() {
		return checkers.newGame();
	}

	public ArrayList<Move> makeMove(ArrayList<Move> moves) {
		ArrayList<Move> revertedMoves = new ArrayList<Move>();

		for (Move m : moves) {
			revertedMoves.add(Move.RevertMove(m));
		}

		return checkers.makeMove(revertedMoves);
	}
}
